package com.miplus.ccrm.core.service.conf;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.conf.PenalEditVo;
import com.miplus.ccrm.core.controller.vo.conf.PenalReqVo;
import com.miplus.ccrm.core.controller.vo.conf.PenalResVo;
import com.miplus.ccrm.core.pojo.FiDistbatchHist;
import com.miplus.ccrm.core.pojo.FiPenaltyHist;
import com.miplus.ccrm.core.mapper.FiPenaltyHistMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author pc
* @description 针对表【fi_penalty_hist】的数据库操作Service实现
* @createDate 2024-04-21 22:47:07
*/
@Service
public class FiPenaltyHistServiceImpl extends MPJBaseServiceImpl<FiPenaltyHistMapper, FiPenaltyHist>
    implements FiPenaltyHistService{

    @Override
    public IPage<PenalResVo> penaltyList(PenalReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                PenalResVo.class,
                new MPJLambdaWrapper<FiPenaltyHist>()
                        .selectAs("fun_getnames('FI.PENAL.REASON',t.reason)", PenalResVo::getReasondsc)
                        .selectAs("(select g.grpname from sys_grp g where g.grpid=t.grpid)", PenalResVo::getGrpname)
                        .selectAll(FiPenaltyHist.class)
                        .eq(JPubUtils.IsNotEmpty(paras.getGrpid()),FiPenaltyHist::getGrpid,paras.getGrpid())
                        .eq(JPubUtils.IsNotEmpty(paras.getReason()),FiPenaltyHist::getReason,paras.getReason())
                        .between(JPubUtils.IsNotEmpty(paras.getStartdt()), FiPenaltyHist::getUpdt,JPubUtils.StringToDate(paras.getStartdt()),JPubUtils.StringToDate(paras.getEnddt()))
                        .orderByDesc(FiPenaltyHist::getUpdt)
        );
    }

    @Override
    public CmdResVo penaltyUpdate(String $usrid, PenalEditVo paras)
    {
        FiPenaltyHist def=new FiPenaltyHist();
        BeanUtils.copyProperties(paras,def);
        def.setUpdt(new Date());
        def.setUpusr($usrid);
        def.setStatus(1);
        int ret=baseMapper.updateById(def);
        return new CmdResVo(ret,def.getHistid().toString());
    }

    @Override
    public CmdResVo penaltyInsert(String $usrid,PenalEditVo paras)
    {
        FiPenaltyHist def=new FiPenaltyHist();
        BeanUtils.copyProperties(paras,def);
        def.setUpdt(new Date());
        def.setUpusr($usrid);
        def.setStatus(1);
        int ret=baseMapper.insert(def);
        return new CmdResVo(ret,def.getHistid().toString());
    }

    @Override
    public CmdResVo penaltyDelete(Integer id)
    {
        int ret= baseMapper.deleteById(id);
        return new CmdResVo(ret,id.toString());
    }
}




